added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSWPFDataBinding / Converters.cs
blobba675e1d8f7f6f8805486cfedf4715545a18108d
1 /************************************* Module Header **************************************\
2 * Module Name: Converters.cs
3 * Project: CSWPFDataBinding
4 * Copyright (c) Microsoft Corporation.
5 *
6 * This example demonstrates how to use DataBinding in WPF
7 *
8 *
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 * History:
14 * * 10/29/2009 3:00 PM Bruce Zhou Created
16 \******************************************************************************************/
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using System.Windows.Data;
23 namespace CSWPFDataBinding
25 public class SalaryFormmatingConverter:IValueConverter
28 #region IValueConverter Members
30 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
32 double dolloars =0;
33 string formattedSalary = string.Empty;
35 if (value == null)
37 throw new NullReferenceException("value can not be null");
39 else
41 Double.TryParse(value.ToString(), out dolloars);
43 formattedSalary = String.Format("Total={0}$", dolloars);
44 return formattedSalary;
47 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
49 double dolloars =0;
50 if (value == null)
52 throw new NullReferenceException("value can not be null");
55 Double.TryParse(value.ToString().TrimStart(new Char[] {'T', 't', 'o', 'a', 'l', '='}).TrimEnd('$'), out dolloars);
56 return dolloars;
59 #endregion